<template>
	<view>
		<view v-for="(item, index) in Message.content" :key="index">
			<Info v-if="item.type == 'info'" :config="item"></Info>
			<Search v-if="item.type == 'Search'" :config="item" @Search="ChangeValue"></Search>
			<Notice v-if="item.type == 'Notice'" :config="item"></Notice>
			<Banner v-if="item.type == 'banner'" :config="item"></Banner>
			<Shop v-if="item.type == 'Shop'" :config="item"></Shop>
			<Images v-if="item.type == 'images'" :config="item"></Images>
			<Goods v-if="item.type == 'product'" :config="item" v-model="page" @GoodsPage="ChagePage" :keyword="keyword" :storeId="storeId"></Goods>
		</view>
		<!-- info,banner,images,product,Search,Shop,Notice -->
	</view>
</template>
<script>
import service_mall from '@/service/mall.js';
import $HTTPS from '@/service/DIY.js';
import Search from '../components/Search.vue';
import Banner from '../components/Banner.vue';
import Images from '../components/Images.vue';
import Shop from '../components/Shop.vue';
import Info from '../components/Info.vue';
import Goods from '../components/Goods.vue';
import Notice from '../components/Notice.vue';
// Notice
export default {
	components: {
		Search,
		Banner,
		Images,
		Shop,
		Info,
		Goods,
		Notice
	},
	data() {
		return {
			storeId: 0,
			useid: '',
			page: 1,
			keyword: '',
			Message: null
			// storeInfo: {},
			// content: null
		};
	},
	onReachBottom() {
		// console.log(123);
		this.page++;
	},
	created() {},
	onLoad(options) {
		// console.log(option);
		this.$utils.getUrl();
		let scene = decodeURIComponent(options.scene); //二维码扫码时的参数
		// console.log(scene, '二维码参数')
		// console.log(options, '转发时参数')
		scene = scene.split('&');
		let obj = {};
		for (let i = 0; i < scene.length; i++) {
			let newscene = scene[i].split('=');
			obj[newscene[0]] = newscene[1];
		}
		// console.log(obj, 'objobj')
		// testCode
		let app = getApp();
		if (obj.store_id) {
			this.storeId = obj.store_id;
		} else if (app.globalData.storeId) {
			this.storeId = app.globalData.storeId;
		} else if (obj.storeId) {
			this.storeId = obj.storeId;
		} else {
			this.storeId = options.storeId;
		}
		// console.log(this.storeId, '店铺id')

		if (app.globalData.share_uid) {
			this.useid = app.globalData.share_uid;
		} else {
			this.useid = uni.getStorageSync('userId');
		}
		// console.log(this.useid, '分享者id')

		let token = uni.getStorageSync('token');
		if (options.share_uid) {
			let shareuId = options.share_uid;
			this.$store.commit('index/SET_shareuId', shareuId);
			if (token && shareuId) {
				service_mall
					.getPromoter({
						share_uid: shareuId
					})
					.then(res => {});
			}
		}
		this.getDetaileMes();
		//收起键盘
		uni.onKeyboardHeightChange(res => {});
	},
	onShareAppMessage(res) {
		let that = this;
		if (res.from === 'button') {
		}
		return {
			title: this.storeInfo.store_name,
			path: '/pages_mall/pages/Decoration/view/index?storeId=' + this.storeId + '&share_uid=' + this.useid,
			success: function(res) {}
		};
	},
	onShareTimeline(res) {
		if (res.from === 'menu') {
		}
		return {
			title: this.storeInfo.store_name,
			path: '/pages_mall/pages/Decoration/view/index?storeId=' + this.storeId + '&share_uid=' + this.useid,
			success: function(res) {}
		};
	},
	mounted() {},
	methods: {
		ChangeValue(params) {
			var that = this;
			that.keyword = params;
			// console.log('123',params);
		},
		ChagePage() {
			this.page = 1;
		},
		getDetaileMes() {
			var that = this;
			$HTTPS
				.GetDiyData({
					partner_id: this.storeId
				})
				.then(res => {
					if (res.code == 1) {
						let data = res.data;
						// console.log(data);
						// that.storeInfo = data.shop;
						data.content = data.content ? JSON.parse(data.content) : [];
						if (data.content.length) {
							data.content.forEach((item, index) => {
								item.shop = data.shop;
							});
						} else {
							uni.redirectTo({
								url: '/pages_mall/pages/mall/store/storeNew?storeId=' + this.storeId
							});
						}
						that.Message = data;
						// console.log(that.content);
					} else {
						that.$utils.showErr({
							title: res.msg
						});
					}
				})
				.catch(err => {
					that.$utils.showErr({
						title: err
					});
				});
		}
	}
};
</script>
<style lang="less" scoped></style>
